<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <link rel="stylesheet" type="text/css" href="/Public/uploadfy/uploadify.css" />
    <script type="text/javascript" src="/Public/uploadfy/jquery.uploadify.min.js"></script>
    <style>
        #dg{
            height: 100%;;
        }
    </style>
</block>
<block name="bdoy">
    <body>
        <table id="grid_outlet_pipe"></table>
        <div id="grid_outlet_pipe_ToolBar" style="padding:5px;height:auto">
            <div style="margin-bottom:5px">
                <a id="btnAdd_outletpipe" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
                <a id="btnedit_outletpipe" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
                <a id="btnDel_outletpipe" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
                <a id="btnSearch_outletpipe" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
                <a id="btnReload" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#grid_outlet_pipe').datagrid({url:'/Manage/AdminPumpOutletPipe/get_all',queryParams:{page:1,rows:20}})">重载</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-import" plain="true" onclick="open_dialog('/Manage/Admin/open_window_import?url=__URL__/import')">导入</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-rescueLog" plain="true" onclick="open_tab('__URL__/export')">导出</a>
            </div>
            <div id="queryParamZone_outletpipe">
                <form id="queryForm_outletpipe" method="post" action="">
                    <table>
                        <tr>
                            <td>泵站</td>
                            <td><input id="ps_id_combox" name="ps_id"></td>
                            <td>出水池</td>
                            <td><select class="easyui-combobox" name="os_id" id="os_id" valueField="id" textField="os_id" data-options="prompt:'{:LANG('pls_input')}'" style="width: 100px;"></select></td>
                            <td>属性</td>
                            <td id="table_field">
                                <input class="easyui-combobox"/>
                            </td>
                            <td>查询条件</td>
                            <td id="condition_td">
                                <input type="text"/>
                            </td>
                            <td><a id="btnQueryMachine" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                            <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#queryForm_outletpipe').form('clear');">重置</a></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div id="outletpipe_Dlg" class="easyui-dialog" title="" style="width:650px;height:300px;padding:10px" buttons="#dlg_buttons_outletpipe" closed="true" resizable="true">
            <form id="outletpipe_Form" method="post" action="">
                <input id="saveflag_outletpipe" name="saveflag_outletpipe" type="hidden" value="add"/>
                <input type="hidden" name="id" />
                <table border="0">
                    <tr>
                        <td align="right">泵站</td>
                        <td><input id="ps_id_combox_1" required="true" name="ps_id" style="width: 150px;"></td>
                        <td>出水池：</td>
                        <td>
                            <select class="easyui-combobox" name="os_id" id="os_id_1" valueField="id" textField="os_id" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 140px;">
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">出水管编码：</td>
                        <td>
                            <input class="easyui-validatebox" validType="maxLength[30]" type="text" name="out_id" required="true"></input>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">出水管管径（毫米）：</td>
                        <td>
                            <input class="easyui-numberbox" type="text" name="out_diameter" precision="3" style="width: 150px;"></input>
                        </td>
                        <td align="right">出水管管底标高（米）：</td>
                        <td>
                            <input class="easyui-numberbox" type="text" name="out_elev" precision="3" style="width: 150px;"></input>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">事故排放口编号：</td>
                        <td>
                            <input class="easyui-numberbox" type="text" name="out_overoutfallid" precision="3" style="width: 150px;"></input>
                        </td>
                        <td align="right">溢流管管径（毫米）：</td>
                        <td>
                            <input class="easyui-numberbox" type="text" name="out_flood_diameter" precision="3" style="width: 150px;"></input>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">溢流管底标高(米)：</td>
                        <td>
                            <input class="easyui-numberbox" type="text" name="out_flood_elev" precision="3" style="width: 150px;"></input>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <div id="dlg_buttons_outletpipe" style="text-align: center;">
            <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submitoutletpipe_Form();">保存</a>
        </div>
        <form id="batchDelForm_outletpipe" method="post">
        </form>
    </body>
</block>
<block name="footExtendJs">
    <script type="text/javascript">
        //$.noConflict();

        $(window).resize(function() {
            $('#grid_outlet_pipe').datagrid('resize');
        });

        function clearoutletpipeForm(){
            $('#outletpipe_Form').form('clear');
        }

        function clearQueryParamZone(){
            $('#queryForm_outletpipe').form('clear');
        }

        $(function(){
            $('#ps_id_combox').combobox({
                url:'/Manage/AdminPumpStation/get_all_combox',
                valueField:'id',
                textField:'name',
                width:180,
                onChange: function (newValue, oldValue) {
                    $('#os_id').combobox('clear');
                    $('#os_id').combobox('reload','/Manage/AdminPumpOutletSum/get_all_fys?ps_id='+newValue);
                }
            });
            $('#ps_id_combox_1').combobox({
                url:'/Manage/AdminPumpStation/get_all_combox',
                valueField:'id',
                textField:'name',
                width:180,
                onChange: function (newValue, oldValue) {
                    $('#os_id_1').combobox('clear');
                    $('#os_id_1').combobox('reload','/Manage/AdminPumpOutletSum/get_all_fys?ps_id='+newValue);
                }
            });
            $('#grid_outlet_pipe').datagrid({
                //title:'出水管',
                width: '100%',
                //height: 400,
                fit: true,
                nowrap: false,
                striped: true,
                collapsible:false,
                url:'/Manage/AdminPumpOutletPipe/get_all',
                queryParams:{'ps_id':$('#pumpstation_id').val(),page:1,rows:20},
                method:'get',
                pageNumber:1,
                pageSize:20,
                idField:'id',
                sortName: 'id',
                sortOrder: 'desc',
                remoteSort: false,
                columns:[[
                    {field:'id',title:'序号',width:60,checkbox:true},
                    {field:'sta_name',title:'泵站名称',width:180,align:'center'},
                    {field:'os_id',title:'出水池编码',width:100},
                    {field:'out_id',title:'出水管编码',width:80},
                    {field:'out_diameter',title:'出水管管径(毫米)',width:80},
                    {field:'out_elev',title:'出水管管底标高(米)',width:80},
                    {field:'out_overoutfallid',title:'事故排放口编号',width:100},
                    {field:'out_flood_diameter',title:'溢流管管径(毫米)',width:100},
                    {field:'out_flood_elev',title:'溢流管底标高(米)',width:100},
                ]],
                pagination:true,
                rownumbers:true,
                singleSelect:true,
                toolbar: '#grid_outlet_pipe_ToolBar',
                onDblClickRow: function(rowIndex, rowData) {
                    var selected = $('#grid_outlet_pipe').datagrid('getSelected');
                    if($('#single').is(":hidden")){
                        edit_outletpipe(rowData.id);
                    }else{
                        var rows = $('#grid_outlet_pipe').datagrid('getSelections');
                        if(selected){
                            if(selected.id == rowData.id){
                                edit_outletpipe(rowData.id);
                            }else{
                                $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                            }
                        }else{
                            edit_outletpipe(rowData.id);
                        }
                    }
                },
                onLoadSuccess: function(data) {
                    $(this).datagrid('resize');
                    $('.pump_select').combobox('reload','/Manage/AdminPumpPump/get_all_pump?ps_id='+$('#pumpstation_id').val());
                }
            });

            $('#btnAdd_outletpipe').click(function() {
                clearoutletpipeForm();
                $("#saveflag_outletpipe").val("add");
                $('#ps_id_combox_1').combobox({
                    url:'/Manage/AdminPumpStation/get_all_combox',
                    valueField:'id',
                    textField:'name',
                });
                $('#outletpipe_Dlg').dialog({title:'录入出水管信息',modal:true});
                $('#outletpipe_Dlg').dialog("open");
            });
            $('#btnedit_outletpipe').click(function() {
                var selected = $('#grid_outlet_pipe').datagrid('getSelected');
                if($('#single').is(":hidden")){
                    if (selected) {
                        edit_outletpipe(selected.id);
                    }
                }else{
                    var rows = $('#grid_outlet_pipe').datagrid('getSelections');
                    if(rows.length == 1 || rows.length == 0){
                        if (selected) {
                            edit_outletpipe(selected.id);
                        }
                        else{
                            $.messager.show({title: "提示",msg: "请选中一条信息，再进行编辑!"});
                        }
                    }else{
                        $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                        singleToggle();
                    }
                }
            });
            $('#btnDel_outletpipe').click(function() {

                var ids = [];
                var rows = $('#grid_outlet_pipe').datagrid('getSelections');
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                if ((ids != null) && (ids.length > 0)) {
                    $.messager.confirm('请确认', '你确定要删除吗？', function(r) {
                        if (r) {

                            $('#batchDelForm_outletpipe').ajaxSubmit({
                                url:"/Manage/AdminPumpOutletPipe/deleteArray",
                                data:{'ids':ids.join(',')},
                                dataType:'json',
                                success: function(data) {
                                    console.log(data);
                                    if (data.status==1) {
                                        $('#grid_outlet_pipe').datagrid('reload');
                                        $('#grid_outlet_pipe').datagrid("unselectAll");
                                        $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                    }
                                    else $.messager.alert('提示','删除失败！','error');
                                }
                            });

                        }
                    });
                }
            });
            $('#btnSearch_outletpipe').click(function() {
                $('#queryParamZone_outletpipe').toggle();
                if($('#queryParamZone_outletpipe').is(":hidden")){
                    clearQueryParamZone();
                }
                $('#grid_outlet_pipe').datagrid("resize");
            });

            $('#btnQueryMachine').click(function() {
                var obj = $('#queryForm_outletpipe').serializeJson();
                $('#grid_outlet_pipe').datagrid('load',obj);
            });
            var model = 'PumpOutletPipe';
            table_index_change(model, 'base');
            $('#queryParamZone_outletpipe').hide();
            $('#single').hide();

            /* WdatePicker({el:'pump_mdate',readOnly:true});
             $dp.hide(); */
        });

        function edit_outletpipe(id) {
            if(id!=""){
                $("#saveflag_outletpipe").val("update");
            }else{
                clearoutletpipeForm();
                $("#saveflag_outletpipe").val("add");
                return;
            }
            $.ajax({url:"/Manage/AdminPumpOutletPipe/get_obj_json",data:{id:id},dataType:"json",success:function(json, textStatus){
                $('#out_id_1').combobox('reload','/Manage/AdminPumpOutletSum/get_all_fys?ps_id='+json.ps_id);
                $('#outletpipe_Form').form('load',{
                    "id": json.id,
                    'ps_id':json.ps_id,
                    "os_id": json.os_id,
                    "out_id": json.out_id,
                    "out_diameter": json.out_diameter,
                    "out_elev": json.out_elev,
                    "out_overoutfallid": json.out_overoutfallid,
                    "out_flood_diameter": json.out_flood_diameter,
                    "out_flood_elev": json.out_flood_elev,

                });
                $('#outletpipe_Dlg').dialog({title:'编辑出水管信息',modal:true});
                $('#outletpipe_Dlg').dialog("open");
                setFormFocus('#outletpipe_Form');
            },error:function(XMLHttpRequest, textStatus, errorThrown) {
                relogin(XMLHttpRequest, textStatus, errorThrown);
            }});
        }

        function submitoutletpipe_Form() {
            if ($('#outletpipe_Form').form('validate')) {
                var submitflag = $("#saveflag_outletpipe").val();
                var url = "";
                console.log(submitflag);
                if (submitflag === "add")
                    url = "/Manage/AdminPumpOutletPipe/add";
                if (submitflag === "update")
                    url = "/Manage/AdminPumpOutletPipe/edit";
                $('#outletpipe_Form').ajaxSubmit({
                    url:url,
                    dataType:'json',
                    success: function(data) {
                        if (data.status==1) {
                            if (submitflag === "add") $('#grid_outlet_pipe').datagrid('load');
                            if (submitflag === "update") $('#grid_outlet_pipe').datagrid('reload');
                            $('#outletpipe_Dlg').dialog("close");
                            $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                        }
                        else $.messager.alert('提示','操作失败！\n原因：'+data.msg,'error');
                    }
                });
            }
        }
    </script>
</block>
